<?php
namespace Datastatistics\Controller;

use Think\Controller;

class Sta
{
	public $num1;
	public $num2;
	public $date;
	/*public function arr_to_str($arr) {
    	foreach ($arr as $v) {
        	$v = join(",",$v); // 可以用implode将一维数组转换为用逗号连接的字符串，join是别名
       	 	$temp[] = $v;
    	}
    	foreach ($temp as $v) {
        	$t.=$v.",";
    	}
    	$t = substr($t, 0, -1); // 利用字符串截取函数消除最后一个逗号
   	 	return $t;
}*/
}
class StatController extends Controller
{
	public function index1()
	{
		if(session('status')>0)
		{
			$this->display();
		}
		else
		{
			$this->error("权限不足");
		}
	}
	public function index2()
	{
		if(session('status')>0)
		{
			$this->display();
		}
		else
		{
			$this->error("权限不足");
		}
	}
	public function getmsg()
	{
		
		//$m=(int)$n;
		/*$t1=strtotime("-1 month");
		$d=date("Y-m-d",$t1);
		echo $d;*/
		$model = M('train');
		$sta[]=new Sta();
		$t=time();
		$y=date("Y",$t);//小写y是18，大写2018
		$m=date("m",$t);
		/*echo $m-1;
		
		for($i=0;$i<5;$i++)
		{
		if($m==1||$m==3||$m==5||$m==7||$m==8||$m==10||$m==11)
		{
			$d=31;
		}
		else if($m==4||$m==6||$m==9||$m==12)
		{
			$d=30;
		}
		else
		{
			if(($y%400==0)||(($y%100!=0)&&($y%4==0)))
			{
				$d=29;
			}
			else
				$d=28;
		}
		$q=$model->where("type='前端' and date between '$y/$m/01' and '$y/$m/$d'")->count();
		$h=$model->where("type='后台' and date between '$y/$m/01' and '$y/$m/$d'")->count();
		dump($q);
		$m--;
		if($m==0)
		{
			$m=12;
			$y--;
		}
	}*/
		for($i=0;$i<5;$i++)
		{
			$q="select count(*) as count from sz_train where month(date)=$m and type='前端' and year(date)=$y";
			$h="select count(*) as count from sz_train where month(date)=$m and type='后台' and year(date)=$y";
			$q2=$model->query($q);
			$sta[$i]->num1=$q2[0]['count'];
			$h2=$model->query($h);
			$sta[$i]->num2=$h2[0]['count'];

			$m=(int) $m;
			$m1="$y-0$m";
			$sta[$i]->date=$m1;
			$m--;
			if($m==0)
			{
				$m=12;
				$y--;
			}
		}
		//dump($q1);
		//dump($h1);
		//dump($m1);
		/*$sta->num1=$q1;
		$sta->num2=$h1;
		$sta->date=$m1;*/
		//dump($sta);
		//dump($q1);
		//dump($sta);
		$this->ajaxReturn($sta);
			//$model1->add();
			//$z=$model1->select();
			//dump($sta);
			//$z[]=$model1;dump($z);
			
		
	
}
	public function getmsg1()
	{
		$model = M('conference');
		$sta[]=new Sta();
		$t=time();
		$y=date("Y",$t);
		$m=date("m",$t);
		for($i=0;$i<5;$i++)
		{
			$q="select count(*) as count from sz_conference where month(date)=$m and sort='研究生会议' and year(date)=$y";
			$h="select count(*) as count from sz_conference where month(date)=$m and sort='本科生会议' and year(date)=$y";
			$q2=$model->query($q);
			$sta[$i]->num1=$q2[0]['count'];
			$h2=$model->query($h);
			$sta[$i]->num2=$h2[0]['count'];
			$m=(int) $m;
			$m1="$y-0$m";
			$sta[$i]->date=$m1;
			$m--;
			if($m==0)
			{
				$m=12;
				$y--;
			}
		}
		$sta->num1=$q1;
		$sta->num2=$h1;
		$sta->date=$m1;
		$this->ajaxReturn($sta);
	}
	public function getmsg2()
	{
		$att=M('Attendance');
		for($i=0;$i<7;$i++)
        {
            $d=7-$i;
            $day=date("Y-m-d",strtotime("-".$d." day"));
            /*$arr[$i]['date']=$day;
            $arr[$i]['typea']=$att->where("date='$day' and stat=1")->count();
            $arr[$i]['typeb']=$att->where("stat=-2 and date='$day'")->count();
            $arr[$i]['typec']=$att->where("stat=-1 and date='$day'")->count();*/
            $arr['date'][$i]=$day;
            $arr['typea'][$i]=$att->where("date='$day' and stat=1")->count();
            $arr['typeb'][$i]=$att->where("stat=-2 and date='$day'")->count();
            $arr['typec'][$i]=$att->where("stat=-1 and date='$day'")->count();
        }
            $this->ajaxReturn($arr);
	}
	public function getmsg3()
	{
		$note=M('note');
		/*$info1=$note->join('join sz_user on sz_user.id=sz_note.edit')->group('sz_note.edit')->avg('score');
		dump($info1);*/
		$con="select name,avg(score) as avg from sz_note,sz_user where sz_note.edit=sz_user.id group by edit";
		$sql=$note->query($con);
		$this->ajaxReturn($sql);
	}
	public function getmsg4()
	{
		$task=M('task');
		$day=I('date');
		$info=$task->field('name,reciver')->where("publictime='2018-07-09'")->select();
		$this->ajaxReturn($info);
	}
}
?>